﻿namespace SanalMagaza.Model.Extentions
{
    using System.Collections.Generic;
    using System.Linq;

    public static class ProductExtention
    {
        public static string GetDefaultImage(this IList<Product> products,long productId)
        {
            var product = products.SingleOrDefault(d => d.Id == productId);
            if (product == null)
                return "/Content/Theme1/images/no-image.jpg";
            var item = product.ProductImageRelations.FirstOrDefault(d => d.IsDefault);
            if (item == null)
                return "/Content/Theme1/images/no-image.jpg";
            return item.ContentUrl;
        }
        public static string GetDefaultImage(this Product product)
        {
            if (product == null)
                return "/Content/Theme1/images/no-image.jpg";
            var item = product.ProductImageRelations.FirstOrDefault(d => d.IsDefault);
            if (item == null)
                return "/Content/Theme1/images/no-image.jpg";
            return item.ContentUrl;
        }
        public static double ByKdv(this Product product)
        {
            return (product.RateKdv * product.Price) / 100;
        }
    }
}